using System.ComponentModel;
using System.Globalization;
using Meebey.SmartIrc4net;

namespace Thunder.Irc.Parser.Default
{
    /// <summary>
    /// Handles the Name message 
    /// </summary>
    internal class MessageParserKick : MessageParser
    {
        /// <summary>
        /// Gets the type of message handled by the parser
        /// </summary>
        public override ReceiveType MessageType
        {
            get { return ReceiveType.Kick; }
        }

        /// <summary>
        /// This method is invoked during message parsing.
        /// </summary>
        /// <param name="args">The <see cref="CancelMessageProcessingEventArgs"/> containing the message to be passed</param>
        /// <remarks>You can cancel further processing of the message by setting the <see cref="CancelEventArgs.Cancel"/> to true</remarks>
        protected override void ParseCore(CancelMessageProcessingEventArgs args)
        {
            this.Manager.RemoveMember(args.MessageData.Channel, args.MessageData.RawMessageArray[3]);

            if (args.MessageData.Message == args.MessageData.Nick)
            {
                this.Manager.WriteText(args.MessageData.Channel, args.MessageData, string.Format(CultureInfo.CurrentCulture, "{0} was kicked by {1}", args.MessageData.RawMessageArray[3], args.MessageData.Nick));
            }
            else
            {
                this.Manager.WriteText(args.MessageData.Channel, args.MessageData, string.Format(CultureInfo.CurrentCulture, "{0} was kicked by {1} => {2}", args.MessageData.RawMessageArray[3], args.MessageData.Nick, args.MessageData.Message));
            }
        }
    }
}